<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head><title>Programming in Lua : 1.3</title>
<link rel="stylesheet" type="text/css" href="pil.css">
</head>
<body>
<p class="warning">
<A HREF="contents.html"><IMG TITLE="Programming in Lua (first edition)" SRC="capa.jpg" ALT="" ALIGN="left"></A>This first edition was written for Lua 5.0. While still largely relevant for later versions, there are some differences.<BR>The third edition targets Lua 5.2 and is available at <A HREF="http://www.amazon.com/exec/obidos/ASIN/859037985X/theprogrammil3-20">Amazon</A> and other bookstores.<BR>By buying the book, you also help to <A HREF="../donations.html">support the Lua project</A>.
</p>
<table width="100%" class="nav">
<tr>
<td width="10%" align="left"><a href="1.2.html"><img border="0" src="left.png" alt="Previous"></a></td>
<td width="80%" align="center"><a href="contents.html"><font face="Helvetica,Arial,sanserif">
<font color="gray">Programming in </font><font color="blue"> Lua</font>
</font></a></td>
<td width="10%" align="right"><a href="1.4.html"><img border="0" src="right.png" alt="Next"></a></td>
</tr>
<tr>
<td width="10%" align="left"></td>
<td width="80%" align="center"><a href="contents.html#P1">Part I. The Language</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="contents.html#1">Chapter 1. Getting Started</a></td>
<td width="10%" align="right"></td></tr>
</table>
<hr/>
<p><a name="lexical"><h2>1.3 &ndash; Some Lexical Conventions</h2></a>

<p>
Identifiers in Lua can be any string of letters,
digits, and underscores,
not beginning with a digit;
for instance
<pre>
    i      j       i10      _ij
    aSomewhatLongName    _INPUT
</pre>
You should avoid identifiers starting with an underscore followed by
one or more uppercase letters (e.g., <code>_VERSION</code>);
they are reserved for special uses in Lua.
Usually,
I reserve the identifier <code>_</code> (a single underscore)
for a dummy variable.

<p>In Lua, the concept of what is a letter is locale dependent.
Therefore, with a proper locale, you can use variable names such as
<code>&iacute;ndice</code> or <code>a&ccedil;&atilde;o</code>.
However, such names will make your program unsuitable to run in
systems that do not support that locale.

<p>The following words are reserved;
we cannot use them as identifiers:
<pre>
    and       break     do        else      elseif
    end       false     for       function  if
    in        local     nil       not       or
    repeat    return    then      true      until
    while
</pre>
Lua is case-sensitive:
<b>and</b> is a reserved word, but <code>And</code> and <code>AND</code>
are two other different identifiers.

<p>A comment starts anywhere with a double hyphen (<code>--</code>)
and runs until the end of the line.
Lua also offers block comments,
which start with <code>--[[</code> and run until the corresponding <code>]]</code>.
A common trick,
when we want to comment out a piece of code,
is to write the following:
<pre>
    --[[
    print(10)         -- no action (comment)
    --]]
</pre>
Now, if we add a single hyphen to the first line,
the code is in again:
<pre>
    ---[[
    print(10)         --> 10
    --]]
</pre>
In the first example, the <code>--</code> in the last line
is still inside the block comment.
In the second example, the sequence <code>---[[</code> does not start
a block comment;
so, the <code>print</code> is outside comments.
In this case, the last line becomes an independent comment,
as it starts with <code>--</code>.

<hr/>
<table width="100%" class="nav">
<tr valign="top">
<td width="90%" align="left">
<small>
  Copyright &copy; 2003&ndash;2004 Roberto Ierusalimschy.  All rights reserved.
</small>
</td>
<td width="10%" align="right"><a href="1.4.html"><img border="0" src="right.png" alt="Next"></a></td>
</tr>
</table>


</body></html>

